package com.fanfanwang.ffw.app.ui.my;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.toolbox.NetworkImageView;
import com.fanfanwang.ffw.app.AppManager;
import com.fanfanwang.ffw.app.R;
import com.fanfanwang.ffw.app.adapter.GlyCarportManagementAdapter;
import com.fanfanwang.ffw.app.base.BaseActivity;
import com.fanfanwang.ffw.app.bean.CarportBean;
import com.fanfanwang.ffw.app.common.StringUtils;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.widget.CommonTitleBar;

/** 管理员 管理停车位，可以进行删除，跳转到添加界面 */
public class GlyMyCarportManagementAct extends BaseActivity {

	private CommonTitleBar commonTitleBar;
	private Activity mAct;
	private Intent mIntent;
	private ListView listview;
	private ArrayList<CarportBean> carportBeans;
	private GlyCarportManagementAdapter adapter;
	public static IDeleteCarportable iDeleteCarportable;
	public static IAddCarportable iAddCarportable;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initView();
		AppManager.getAppManager().addActivity(this);
		initData();
		setListener();
	}

	@Override
	public void initView() {
		// TODO Auto-generated method stub
		setContentView(R.layout.gly_activity_my_carport_management);
		mAct = this;
		commonTitleBar = (CommonTitleBar) findViewById(R.id.common_titlebar);
		listview=(ListView)findViewById(R.id.lv_carport);

		carportBeans=new ArrayList<CarportBean>();
		getList();
		setDeleteInterface();
		adapter=new GlyCarportManagementAdapter(mAct, carportBeans);
	}
	public void getList(){
		CarportBean carportBean1=new CarportBean();
		CarportBean carportBean2=new CarportBean();
		CarportBean carportBean3=new CarportBean();
		carportBean1.carport_num="0";
		carportBean2.carport_num="1";
		carportBean3.carport_num="2";
		carportBeans.add(carportBean1);
		carportBeans.add(carportBean2);
		carportBeans.add(carportBean3);
	}
	@Override
	public void setListener() {
		commonTitleBar.setToolBarReturnOnclickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
		commonTitleBar.setRightView(getString(R.string.add), new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				mIntent=new Intent(GlyMyCarportManagementAct.this, GlyMyAddCarportAct.class);
				startActivity(mIntent);
			}
		});
	}

	@Override
	public void initData() {
		// TODO Auto-generated method stub
		commonTitleBar.setCenterText(getString(R.string.carport_management));
		commonTitleBar.setReturnVisible();
		listview.setAdapter(adapter);
	}
	public void setDeleteInterface(){
		iDeleteCarportable=new IDeleteCarportable() {
			
			@Override
			public void deleteCarport(int pos) {
				// TODO Auto-generated method stub
				carportBeans.remove(pos);
				adapter.resetData(carportBeans);
				adapter.notifyDataSetChanged();
			}
		};
		iAddCarportable=new IAddCarportable() {
			
			@Override
			public void addCarport(CarportBean carportBean) {
				// TODO Auto-generated method stub
				carportBeans.add(carportBean);
				adapter.resetData(carportBeans);
				adapter.notifyDataSetChanged();
			}
		};
		
	}
	public interface IDeleteCarportable{
		public void deleteCarport(int pos);
	}
	public interface IAddCarportable{
		public void addCarport(CarportBean carportBean);
	}
}
